<template>
  <div>
    <div class="box">
      <div class="box-body">
        <el-form :inline="true" :model="query" label-position="top">
          <el-form-item label="有效期:">
            <el-col :span="11">
              <el-date-picker v-model="query.validFrom" type="date" placeholder="起始时间" />
            </el-col>
            <el-col :span="2" class="text-center">至</el-col>
            <el-col :span="11">
              <el-date-picker v-model="query.validTo" type="date" placeholder="截止时间" />
            </el-col>
          </el-form-item>
          <el-form-item label="USJ Item Code:">
            <el-input v-model="query.usjItemId"></el-input>
          </el-form-item>
          <el-form-item label="产品编码:">
            <el-input v-model="query.itemId"></el-input>
          </el-form-item>
          <el-form-item label="产品名称:">
            <el-input v-model="query.itemName"></el-input>
          </el-form-item>
          <el-form-item label="" class="no-top-label">
            <el-button type="primary" icon="search" @click="loadPage(1)">检索</el-button>
          </el-form-item>
        </el-form>
      </div>
    </div>
  
    <el-table :data="page.content" border v-on:sort-change="sort">
      <el-table-column prop="usjItemId" label="USJ Item Code" width="180" column-key="usj_item_id" sortable="custom"/>
      <el-table-column prop="itemId" label="产品编码" width="120" column-key="item_id" sortable="custom"  />
      <el-table-column prop="itemName" label="产品名称" width="300" column-key="item_name" sortable="custom"/>
      <el-table-column prop="validStartDate" label="起始有效期" column-key="valid_start_date" sortable="custom" />
      <el-table-column prop="validEndDate" label="有效期截止"  column-key="valid_end_date" sortable="custom" />
      <el-table-column label="操作" width="120">
        <template slot-scope="scope">
          <el-button type="primary" size="small">编辑</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination @current-change="showPage" :current-page.sync="page.page" :page-size="page.pageSize" 
      :total="page.totalElements" layout="total, prev, pager, next, jumper" />
  </div>
</template>

<script>
import { Items } from '@/store/api'
import Pagination from '@/utils/pagination'

export default {
  created() {
    this.loadPage(1)
  },
  data() {
    return {
      loading: false,
      page: {
        content: []
      },
      query: {
        validFrom: Date.now(),
        validTo: null,
        status: null
      }
    }
  },
  methods: {
    ...Pagination,
    list(page, query) {
      this.loading = true
      return Items.listUsjItems(query).then((data) => {
        this.page = data
        this.loading = false
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.el-input {
  width: 100%;
}

.display-form .display-item label {
  width: 100px;
}
</style>
